#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>

int *converStorage(int **nums, int n){
    int *arr = (int*)malloc(sizeof(int)*(3*n-1));
    int k=1;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(nums[i][j]){
                arr[k++] = nums[i][j];
            }
        }
    }
    return arr;
}

int main(){
    printf("enter the size of this matrix n:\n");
    int n ;
    scanf("%d", &n);
    int **nums = (int **)malloc(sizeof(int*)*n);
    for(int k=0;k<n;k++)
        nums[k] = (int*)malloc(sizeof(int)*n);
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            scanf("%d", &nums[i][j]);
    int *arr = converStorage(nums, n); 
    int len = 3*n-1;
    for(int i=1;i<len;i++)
        printf("%d ", arr[i]);
    printf("\n");
    return 0;
}